/**
 * @file 引入axios导入到vue里
 *
 * @author fanxingguang@baidu.com
 * 2017-05-04
 */
import axios from 'axios';

let doAxios = (...args) => {
    return new Promise((resolve, reject) => {
        axios(...args).then((res) => {
            let data = res.data;
            if (res.status === 200) {
                let status = data.status !== undefined ? data.status : data.code;
                if (status > 0) {
                    reject(data)
                } else {
                    resolve(data);
                }
            } else {
                reject(data)
            }
        }, (res) => {
            reject(res);
        });
    });
}

export default {
    install(Vue) {
        Vue.prototype.$axios = doAxios;
    }
}